//
//  EMRepayProgressView.m
//  EasyMoney
//
//  Created by zh on 2020/1/11.
//  Copyright © 2020 zh. All rights reserved.
//

#import "EMRepayProgressView.h"
#import "EMProgressGradientView.h"

@interface EMRepayProgressView ()

@property (nonatomic, strong) EMProgressGradientView *progressView;
@property (nonatomic, strong) UILabel *repayDaysLabel;
@property (nonatomic, strong) UILabel *repayDateLabel;

@end

@implementation EMRepayProgressView


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}
- (void)setupUI{

    CGRect progressRect = CGRectMake(77, 46, SCREEN_WIDTH-154, 250);
    EMProgressGradientStyleModel *style = [[EMProgressGradientStyleModel alloc]init];
    style.lineWidth = 14;
    style.backgroundColor = ColorFromRGB(0xEEEEEE);
    style.startColor = ColorFromRGB(0x36B2FF);
    style.endColor = ColorFromRGB(0x2761FF);
    style.origin = CGPointMake((SCREEN_WIDTH-154) / 2, (SCREEN_WIDTH-154) / 2+30);
    style.startAngle = -M_PI-(M_PI_2/3);
    style.endAngle = (M_PI_2/3);
    style.radius = (SCREEN_WIDTH-154)*0.5;

    self.progressView = [[EMProgressGradientView alloc]initWithFrame:progressRect ProgressGradientModel: style];
    [self addSubview:self.progressView];

    //
    UILabel *dayLabel = [[UILabel alloc]init];
    dayLabel.textColor = ColorFromRGB(0x999999);
    dayLabel.font = FONT_PINGFANG_REGULAR_(14);
    dayLabel.text = NSLocalizedString(@"到期", nil);
    [self addSubview:dayLabel];
    [dayLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.mas_equalTo(125);
        make.height.mas_equalTo(20);
    }];

    UIView *dayView = [[UIView alloc]init];
    [self addSubview:dayView];
    [dayView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(dayLabel.mas_bottom).offset(2);
    }];
    
    self.repayDaysLabel = [[UILabel alloc]init];
    self.repayDaysLabel.textColor = ColorFromRGB(0x333333);
    self.repayDaysLabel.font = FONT_PINGFANG_MEDIUM_(35);
    [dayView addSubview:self.repayDaysLabel];
    [self.repayDaysLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(dayView);
        make.centerY.equalTo(dayView);
        make.height.equalTo(dayView);
    }];

    UILabel *unitLabel = [[UILabel alloc]init];
    unitLabel.text = NSLocalizedString(@"天", nil);
    unitLabel.textColor = ColorFromRGB(0x333333);
    unitLabel.font = FONT_PINGFANG_REGULAR_(16);
    [dayView addSubview:unitLabel];
    [unitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.repayDaysLabel.mas_right).offset(10);
        make.right.equalTo(dayView);
        make.baseline.equalTo(self.repayDaysLabel);
    }];

    UILabel *dateLabel = [[UILabel alloc]init];
    dateLabel.textColor = ColorFromRGB(0x999999);
    dateLabel.font = FONT_PINGFANG_REGULAR_(14);
    dateLabel.text = NSLocalizedString(@"到期日", nil);
    [self addSubview:dateLabel];
    [dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(dayView.mas_bottom).offset(20);
    }];

    self.repayDateLabel = [[UILabel alloc]init];
    self.repayDaysLabel.textColor = ColorFromRGB(0x333333);
    self.repayDateLabel.font = FONT_PINGFANG_REGULAR_(14);
    [self addSubview:self.repayDateLabel];
    [self.repayDateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(dateLabel.mas_bottom).offset(2);
    }];
}

- (void)setModel:(EMRepaymentResponseModel *)model{
    _model = model;

    self.progressView.progress = [model.progress floatValue];
    self.repayDaysLabel.text = model.repayDays;
    self.repayDateLabel.text = model.repayDate;
}

@end
